.TH std::basic_filebuf::operator= 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::basic_filebuf::operator= \- std::basic_filebuf::operator=

.SH Synopsis
   std::basic_filebuf& operator=( std::basic_filebuf&& rhs );         \fB(1)\fP \fI(since C++11)\fP
   std::basic_filebuf& operator=( const std::basic_filebuf& rhs ) =   \fB(2)\fP
   delete;

   Assigns another basic_filebuf object.

   1) First calls close() to close the associated file, then moves the contents of rhs
   into *this: the put and get buffers, the associated file, the locale, the openmode,
   the is_open flag, and any other state. After the move, rhs is not associated with a
   file and rhs.is_open() == false.
   2) The copy assignment operator is deleted; basic_filebuf is not CopyAssignable.

.SH Parameters

   rhs - another basic_filebuf that will be moved from

.SH Return value

   *this

.SH Example


// Run this code

 #include <cassert>
 #include <fstream>
 #include <iostream>
 #include <string>

 int main()
 {
     std::ofstream{"test.in"} << "test\\n"; // writes via a temporary object
     std::ifstream fin("test.in"); // read-only stream
     std::ofstream fout("test.out"); // write-only stream

     std::string s;
     std::getline(fin, s);
     std::cout << "s = [" << s << "]\\n"; // s contains "test"

     assert(fout.is_open());
     *fin.rdbuf() = std::move(*fout.rdbuf());
     assert(!fout.is_open());

     std::getline(fin, s);
     std::cout << "s = [" << s << "]\\n"; // s is empty input
 }

.SH Output:

 s = [test]
 s = []

.SH See also

   constructor   constructs a basic_filebuf object
                 \fI(public member function)\fP
   swap          swaps two basic_filebuf objects
   \fI(C++11)\fP       \fI(public member function)\fP
